import {TOKEN_NAME, USER_INFO} from "~/common/constants";
import {serialize, deserialize} from './parse'
export function getLocalUserInfo () {
  if (process.client) {
    return deserialize(localStorage.getItem(USER_INFO))
  }
  return null
}
export function setLocalUserInfo(infos?: Record<string, unknown> | undefined) {
  if (infos) {
    if (process.client) {
      localStorage.setItem(USER_INFO, serialize(infos))
    }
  } else {
    const userToken = useCookie(TOKEN_NAME)
    if (userToken.value) userToken.value = null
    if (process.client) {
      localStorage.removeItem(USER_INFO)
    }
  }
}
